package com.hongxun.modules.eys.controller;

import java.util.List;
import java.util.Map;

import com.hongxun.modules.bss.entity.DCrossCostEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hongxun.modules.eys.entity.ECrossCostEntity;
import com.hongxun.modules.eys.service.ECrossCostService;
import com.hongxun.common.utils.PageUtils;
import com.hongxun.common.utils.Query;
import com.hongxun.common.utils.R;




/**
 * 交叉跨越及工程量
 * 
 * @author zkcn
 * @email youeremail@163.com
 * @date 2018-09-18 14:14:27
 */
@RestController
@RequestMapping("/eys/ecrosscost")
public class ECrossCostController {
	@Autowired
	private ECrossCostService eCrossCostService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
        String wheres =" 1=1 ";
		if(query.get("pGuid")!=null&&!query.get("pGuid").toString().equals(""))
		{
			wheres+=" and  p_guid = '" + query.get("pGuid").toString()+"' ";
		}
		if(query.get("dpGuid")!=null&&!query.get("dpGuid").toString().equals(""))
		{
			wheres+=" and  (c_c_downguid = '" + query.get("dpGuid").toString()+"' " +
					" or c_c_upguid = '" + query.get("dpGuid").toString()+"') " ;
		}
		wheres+=" and  c_c_datastate != '删除' ";
        query.put("filterSql",wheres+" ");
		List<ECrossCostEntity> eCrossCostList = eCrossCostService.queryList(query);
		int total = eCrossCostService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(eCrossCostList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}

	@RequestMapping("/select")
	public R select(@RequestParam Map<String, Object> params){
		//查询列表数据
		Query query = new Query(params);
		String wheres =" 1=1 ";
		if(query.get("pGuid")!=null&&!query.get("pGuid").toString().equals(""))
		{
			wheres+=" and  p_guid = '" + query.get("pGuid").toString()+"' ";
		}
		if(query.get("dpGuid")!=null&&!query.get("dpGuid").toString().equals(""))
		{
			wheres+=" and  (c_c_downguid = '" + query.get("dpGuid").toString()+"' " +
					" or c_c_upguid = '" + query.get("dpGuid").toString()+"') " ;
		}
		wheres+=" and  c_c_datastate != '删除' ";
		query.put("filterSql",wheres+" ");
		List<ECrossCostEntity> eCrossCostList = eCrossCostService.queryList(query);

		return R.ok().put("returnlist", eCrossCostList);
	}

	/**
	 * 信息
	 */
	@RequestMapping("/info/{guid}")
	public R info(@PathVariable("guid") String guid){
		ECrossCostEntity eCrossCost = eCrossCostService.queryObject(guid);
		
		return R.ok().put("eCrossCost", eCrossCost);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	public R save(@RequestBody ECrossCostEntity eCrossCost){
		eCrossCostService.save(eCrossCost);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	public R update(@RequestBody ECrossCostEntity eCrossCost){
		eCrossCostService.update(eCrossCost);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	public R delete(@RequestBody String[] guids){
		eCrossCostService.deleteBatch(guids);
		
		return R.ok();
	}
	
}
